package com.inspector.app.di.persistence.plot

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class MapDaoConverters {

    @TypeConverter
    fun listToJson(list: MutableList<MapPoint>?): String? {
        try {
            return Gson().toJson(list)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return null
    }

    @TypeConverter
    fun jsonToList(json: String?): MutableList<MapPoint>? {
        try {
            return Gson().fromJson<MutableList<MapPoint>>(
                    json, object : TypeToken<MutableList<MapPoint>>() {}.type)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return null
    }
}